package com.zk.mall.service.impl;

import com.zk.mall.dao.UserDao;
import com.zk.mall.entity.User;
import com.zk.mall.service.IUserService;
import com.zk.mall.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户注册
 */
public class UserServiceImpl implements IUserService {
    SqlSession session= SqlSessionFactoryUtil.getSqlSession();
    UserDao userDao=session.getMapper(UserDao.class);
    @Override
    public int adduser(User user){
        int result=0;
        try{
            result=userDao.adduser(user);
            if(result>0){
                session.commit();
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            session.close();
        }
        return result;
    }
    public List<User> userList(){
        List<User> userList=new ArrayList<>();
        try{
           userList=userDao.userlist();
        }catch (Exception e){
            e.printStackTrace();
        }
        return userList;

    }



}
